<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家作品控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajucaseController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete_deep',
			'input_change_unique',
			'forbid',
			'resume',
			'clear_recycle',
			'save_sort'
		);
		
		parent::init__();
	}
	
	public function filter_(&$arrMap){
		$arrMap['A.jiajucase_title']=array('like',"%".Q::G('jiajucase_title')."%");
		$arrMap['A.jiajucase_picnum']=array('egt',intval(Q::G('jiajucase_picnum')));
		$arrMap['A.jiajucase_viewnum']=array('egt',intval(Q::G('jiajucase_viewnum')));
		$arrMap['A.jiajucase_realprice']=array('egt',intval(Q::G('jiajucase_realprice')));
		$arrMap['A.jiajucase_realspace']=array('egt',intval(Q::G('jiajucase_realspace')));
		$arrMap['A.jiajucompany_id']=$GLOBALS['_company_']['jiajucompany_id'];
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);
	}

	public function bAdd_(){
		// 作品属性
		$oJiajucompanyclass=Q::instance('JiajucompanyclassModel');
		$this->assign('arrStyleclass',$oJiajucompanyclass->getClass(52));
		$this->assign('arrSpaceclass',$oJiajucompanyclass->getClass(53));
		$this->assign('arrPriceclass',$oJiajucompanyclass->getClass(50));
		$this->assign('arrAreaclass',$oJiajucompanyclass->getClass(51));

		// 设计师
		$arrDesignerids=Model::F_('jiajudesigner','jiajucompany_id=? AND jiajudesigner_status=1',$GLOBALS['_company_']['jiajucompany_id'])
			->setColumns('jiajudesigner_id,jiajudesigner_name')
			->getAll();
		$this->assign('arrDesignerids',$arrDesignerids);
	}

	public function bEdit_(){
		$nId=intval(Q::G('id','G'));
		// 作品内容
		$sContent=JiajucasecontentModel::F('jiajucase_id=?',$nId)->getColumn('jiajucase_content');
		$this->assign('sContent',$sContent);

		$this->bAdd_();
	}

	protected function AEditObject_($oModel){
		if(in_array($oModel->jiajucase_status,array(9,3)) || $oModel->jiajucompany_id!=$GLOBALS['_company_']['jiajucompany_id']){
			$this->E('你没有权限访问。');
		}
	}

	public function insert($sModel=null,$nId=null){
		$oJiajucase=new JiajucaseModel();
		$oJiajucase->saveData($GLOBALS['_company_']);
		if($oJiajucase->isError()){
			$this->E($oJiajucase->getErrorMessage());
		}

		$this->A($oJiajucase->toArray(),'作品添加成功',1);
	}

	public function update($sModel=null,$nId=null){
		$nId=intval(Q::G('id'));

		$oJiajucase=JiajucaseModel::F('jiajucase_id=?',$nId)->getOne();
		$oJiajucase->updateData($GLOBALS['_company_']);
		if($oJiajucase->isError()){
			$this->E($oJiajucase->getErrorMessage());
		}

		$this->S('作品更新成功');
	}

}
